//针对 url 查询字符串中参数的获取
const http = require('http');

const server = http.createServer((request, response) => {
    //实例化 URL 对象
    let myURL = new URL(request.url, 'http://127.0.0.1');
    //获取颜色
    let bg = myURL.searchParams.get('bg');
    //设置响应结果的显示颜色
    response.end(`<!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>网站首页</title>
        <style>
            body{
                background: ${bg ? bg : 'pink'};
            }
        </style>
    </head>
    <body>
    </body>
    </html>`);
});

server.listen(80, () => {
    console.log('服务已经启动.....');
})